/*
 * LimitsChecker.h
 *	list of methods to replace std::numeric_limits::epsilon return value
 *  Created on: Oct 13, 2012
 *      Author: pigmal
 */

#ifndef LIMITSCHECKER_H_
#define LIMITSCHECKER_H_

#include<limits.h>
#include<madmath.h>

#ifndef FLT_EPSILON
	#define FLT_EPSILON 0.0000001
#endif

#ifndef INT_EPSILON
	#define INT_EPSILON 1
#endif

template<typename T>
struct TypeParseTraits;

#define REGISTER_PARSE_TYPE(X) template <> struct TypeParseTraits<X> \
{ static const char* name; } ; const char* TypeParseTraits<X>::name = #X
REGISTER_PARSE_TYPE(int);
REGISTER_PARSE_TYPE(double);
REGISTER_PARSE_TYPE(float);

template <typename T>
T GetEpsilonVal()
{
	if(TypeParseTraits<T>::name[0] == 'f')//need only to compare the first letter
	{
		return FLT_EPSILON;
	}

	if(TypeParseTraits<T>::name[0] == 'd')
	{
		return DBL_EPSILON;
	}

	if(TypeParseTraits<T>::name[0] == 'i')
	{
		return INT_EPSILON;
	}

	return 0;
}


#endif /* LIMITSCHECKER_H_ */
